package com.iting.test.filter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author iting Nie
 * @version 1.1
 * @create 2021/11/17
 */
public class MyDateConvert implements Converter<String, Date> {

    @Override
    public Date convert(String s) {
        System.out.println("MyDateConvert方法执行了");
        Date parse = null;
        try {
            if (s.contains("-")){
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                parse = simpleDateFormat.parse(s);
            } else if (s.contains("/")){
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
                parse = simpleDateFormat.parse(s);
            }else {
            	parse = new Date();
			}

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return parse;
    }
}
